<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #content{
            width: 800px;
            height: 20px;
            border: solid 1px #ccc;
            position: relative;
        }
        #jindu{
            height: 20px;
            background: pink;
        }
        #content span{
            position: absolute;
            top: 0;
            left: 5px;
        }
    </style>
</head>
<body>
    <div id="content">
        <div id="jindu" style="width: 0px"></div>
        <span id="num">0%</span>
    </div>
</body>
<script>
    var time = setInterval(function(){
        // 获取jinsu的width，用parseInt将px去掉
        var style = parseInt(jindu.style.width);
        // 将获取到的width增加10
        var currWidth = style + 10; 
        // 判断width增加10的值是否大于或者等于800
        if(currWidth >= 800){
            // 超过800强制令它等于800，同时清除计数器
            currWidth = 800;
            clearInterval(time)
        }
        // 将width增加10后的值赋给jindu的width
        jindu.style.width = currWidth + "px";

        // 让数字和进度条同步增加width
        num.style.left = currWidth + 3 + "px";
        // 把数字变成百分比，用当前的width除上总长度
        num.innerHTML = ((currWidth/800)*100).toFixed(2) + "%";
    },100)
</script>
</html>